module MuIDE
  # encapsulate the core components 

#   /=begin
#      main nav
#      main aui (nb menu etc)
#      main frame
#   /=end
class ObjectEditor
  attr_accessor :type,:attribute
  def initialize(type,attribute,obj)
    @type,@attribute,@obj=type,attribute,obj
  end
  def update value
    @obj.attributes[type][@attribute] = value
    if @obj.functions.has_key?(@attribute)
     @obj.functions[@attribute] = @obj.attributes[type][@attribute]
    elsif @obj.commands.has_key?(@attribute)
     @obj.commands[@attribute] = @obj.attributes[type][@attribute]
    end
    @obj.write
  end
end
  class BaseGUIframe < Wx::Frame
  consts = %w[
        ID_CreateTree
        ID_CreateGrid
        ID_CreateText
        ID_CreateHTML
        ID_CreateNotebook
        ID_CreateSizeReport
        ID_GridContent
        ID_TextContent
        ID_TreeContent
        ID_HTMLContent
        ID_NotebookContent
        ID_SizeReportContent
        ID_CreatePerspective
        ID_CopyPerspectiveCode
        ID_AllowFloating
        ID_AllowActivePane
        ID_TransparentHint
        ID_VenetianBlindsHint
        ID_RectangleHint
        ID_NoHint
        ID_HintFade
        ID_NoVenetianFade
        ID_TransparentDrag
        ID_NoGradient
        ID_VerticalGradient
        ID_HorizontalGradient
        ID_Settings
        ID_NotebookNoCloseButton
        ID_NotebookCloseButton
        ID_NotebookCloseButtonAll
        ID_NotebookCloseButtonActive
        ID_NotebookAllowTabMove
        ID_NotebookAllowTabExternalMove
        ID_NotebookAllowTabSplit
        ID_NotebookWindowList
        ID_NotebookScrollButtons
        ID_NotebookTabFixedWidth
        ID_NotebookArtGloss
        ID_NotebookArtSimple ]
  
  consts.each_with_index do | c, i |
    const_set(c, 2000 + i) 
  end
  ID_FirstPerspective = ID_CreatePerspective + 1000
     attr_accessor :activeObjectEdit,:exts
     def initialize(*args)
        super *Initializer::new(args).super_frame
        @mgr = Wx::AuiManager.new
	@mgr.set_managed_window(self)
	projects = []
	@pM = PaneMatrix::new(self)
	# set up default notebook style
	@notebook_style = Wx::AUI_NB_DEFAULT_STYLE|Wx::AUI_NB_TAB_EXTERNAL_MOVE|Wx::NO_BORDER|Wx::EXPAND|Wx::ALL|Wx::GROW
	@notebook_theme = 0
        @perspectives = []
	setup_menu
	create_status_bar 2
	get_status_bar.set_status_text("Ready",0)
        get_status_bar.set_status_text("Offline mode",1)
	set_min_size( Wx::Size.new(1000,600) )

	setup_toolbars
	setup_panes
# p @tree_id
# 	setup_perspectives
	setup_events
        $projects={}
        $pobjects={}
        setup_inputs(@ui,@styled)
        @server = YAML::load_file "data/offlinePenn-default_server.scfg"
p @server
        load_projects
        @styled.set_text File::open("libs/utilities/extra/sample_timer.rb",'r').readlines.join
	@mgr.update
        @logfile = "logs/#{Time.now.to_s}_logfile.log"
        $logfile = @logfile
        @exts={}
        load_ext "libs/gui/extra/config/chat_config.rb"
        @pM.panes.each {|pa|
          pa.left_dockable,pa.right_dockable,pa.top_dockable,pa.floatable = 1,1,1,1
          pa.movable(1)
        }
        setup_perspectives
        @pM.show
     end
  def append_log mess
    str = @log.value+"\n"+Time.now.to_s+": "+mess
    @log.value = str
    File.open(@logfile,"w") {|f| f.puts str}
  end
  def show_content(int)
#     e_id = event.get_id
#     @mgr.get_pane("grid_content").show(e_id == ID_GridContent)
    @mgr.get_pane("editor_content").show(int == 0)
    @mgr.get_pane("html_content").show(int == 7)
    @mgr.get_pane("yaml_content").show(int == 3)
    @mgr.get_pane("muclient_content").show(int == 4)
    @mgr.get_pane("proj1_edit").show(int == 2)
    @mgr.get_pane("extension_content").show(int == 5)
    @mgr.get_pane("attViewer_content").show(int == 1)
    @mgr.get_pane("object_content").show(int == 2)
    @mgr.get_pane("ilf_content").show(int == 6)
#     @mgr.panes.find {|pane| pane.floating?}.show
    @mgr.update
#     show_with(int)
  end
  def show_with(int)
    ext = @exts.find_all {|e| e[1].shows_with==int}
    if ext.class == Array
      ext.each {|e|
        @mgr.get_pane(e[1].ext_name).show(int==e[1].shows_with)
      }
    end
#     ext = @exts.find_all {|e| e[1].shows_with!=int}
#     if ext.class == Array
#       ext.each {|e|
#         @mgr.get_pane(e[1].ext_name).hide()
#       }
#     end
  end
  def add_ext(ins,panel)
    @exts[ins::ext_name]=ins
    pi = Wx::AuiPaneInfo::new
    pi.set_name(ins.ext_name).set_caption(ins.ext_name).right.show(1)
    pi.left_dockable,pi.right_dockable,pi.top_dockable,pi.top_dockable=1,1,1,1
    pi.set_close_button.set_maximize_button
# p ins
# p pi
    @mgr.add_pane panel,pi
    @pM.add pi
#     @mgr.update
#     @mgr.get_pane(ins.ext_name).float
#     @mgr.update
#     @mgr.get_pane(ins.ext_name).dock
#     @mgr.update
# #     @mgr.get_pane(ins.ext_name).dock.hide
#     @mgr.get_pane(ins.ext_name).bottom
    @mgr.update
    
  end
  def load_ext(file)
    eval File.open(file,"r").readlines.join
  end
  def setup_events
    evt_menu(1234) {|evt| on_connect }
    evt_menu(1235) {|evt| on_disconnect }
    evt_menu(1236) {|evt| on_newProject }
    evt_menu(1237) {|evt| on_loadProject }
    evt_menu(ID_CreatePerspective) { | e | on_create_perspective } 
    evt_menu(ID_CopyPerspectiveCode) { | e | on_copy_perspective_code} 
    30.times do |i|
      evt_menu(ID_FirstPerspective+i) { | e | on_restore_perspective(e);p "=\n"*12 }
    end
    evt_tree_item_activated(@tree_id) { | event |
      item = @uiAppItems.index(event.get_item) 
      if item
        show_content(item)
      else
      end
    }
    evt_tree_item_activated(@ptree_id) { | event |
      item = @ptree.get_item_data(event.get_item) 
      
      if item[1].class==PObj
#         p item[0][event.get_string)]
p event.get_string.downcase
# exit
        @pm.n.value=@ptree.get_item_text(event.get_item)
p item
        if item[0].class == Symbol
          val = item[1].attributes[item[0]][@ptree.get_item_text(event.get_item)]
        else
          val = item[1].instance_variable_get("@"+item[0])[@ptree.get_item_text(event.get_item)]
        end
        @pm.attEdit.value = val
        @activeObjectEdit = ObjectEditor::new(:and,@ptree.get_item_text(event.get_item),item[1])
      else
      end
    }
  end
  def get_object_list
    return @object_list
  end
  def on_connect
     dlg = Wx::FileDialog.new(self, "Chhose a server config file",
     "", "", "Server Config Files(*.scfg)|*.scfg",
     Wx::OPEN, Wx::DEFAULT_POSITION)    #
     dlg.set_directory("#{Dir.getwd}/data")
     dlg.show_modal
     file = dlg.get_path
     @server = YAML::load_file file
     clear_projects
     load_projects
# p server
    connector = Connector::new(@server,@ui,self)
    connector.do_connect
# p server
    get_status_bar.set_status_text("Online mode",1)
    append_log "Connected to #{@server.sname}: #{@server.host} - #{@server.port}"
    @online = 1
  end
  def online?
    if @online
      return 1
    end
  end
  def load_projects()
     if !@server.projects.empty?
       @server.projects.each_key {|k|
          add_project k.to_s
          pj = YAML.load_file(@server.projects[k])
          $projects[pj.pname]=pj
#           add_project pj.pname
#           @ptree.items[p.pname]=
          pj.objects.each {|o|
            obj = YAML.load_file o
            add_pobj k.to_s,obj.dbref+" -- "+obj.oname,obj
         }
       }
     end
  end
  def clear_projects
    @ptree.delete_all_items
    @ptree.root = @ptree.add_root("Projects",0)
  end
  def add_pobj(p1,o,obj=nil)
    p @ptree.items#;exit
    item = @ptree.items[p1]
# p p1;exit
    it = @ptree.append_item(item,o,0)
    cmds=@ptree.append_item(it,"Commands",0)
    fun=@ptree.append_item(it,"Functions",0)
    atty=@ptree.append_item(it,"Attributes",0)
    attyAt=@ptree.append_item(atty,"@ ('hard')",0)
    attyAnd=@ptree.append_item(atty,"& ('soft')",0)
    obj.functions.each_key {|f|
      @ptree.set_item_data(@ptree.append_item(fun,f.to_s,1),["functions",obj])
    }
    obj.commands.each_key {|f|
      @ptree.set_item_data(@ptree.append_item(cmds,f.to_s,1),["commands",obj])
    }
    obj.attributes[:at].each_key {|f|
      @ptree.set_item_data(@ptree.append_item(attyAt,f.to_s,1),[:at,obj]) 
    }
    obj.attributes[:and].each_key {|f|
      @ptree.set_item_data(@ptree.append_item(attyAnd,f.to_s,1),[:and,obj]) 
    }
    $pobjects[obj.oname]=obj
    append_log "Added #{obj.oname}"
  end
  def add_project(pj)
    @ptree.items[pj]=@ptree.append_item(@ptree.root,pj,0)
    append_log "Added project #{pj}"
  end
  def on_disconnect

  end
  def on_newProject()
    pname = Wx::TextEntryDialog::new self,"Enter a name to be associated with this project.","Enter a project name","new_proj"
    case pname.show_modal
      when Wx::ID_OK
        pn = pname.value
    end  
    proj = Project::new @server.cfg,pn
    add_project pn
    @server.projects[proj.pname]=proj.cfg
    @server.write
    proj.write 
    append_log "created project #{pn}"
  end
  def on_loadProject
#      @panel.evt_button(3337) {|evt|
       dlg = Wx::FileDialog.new(self, "Choose a project config file",
       "", "", "Project Config Files(*.pcfg)|*.pcfg",
       Wx::OPEN, Wx::DEFAULT_POSITION)    #
       dlg.set_directory("#{Dir.getwd}/data")
       dlg.show_modal
       file = dlg.get_path
       
# #     }
    proj = YAML::load_file(file)
    add_project proj.pname
    proj.objects.each {|o|
          obj = YAML.load_file o
          add_pobj proj.pname,obj.dbref+" -- "+obj.oname,obj
    }
  end
  def setup_menu
    mb = Wx::MenuBar.new

    file_menu = Wx::Menu.new
    file_menu.append(1234,"Connect to server")
    file_menu.append(1235,"Disconnect")
    file_menu.append(Wx::ID_EXIT, "Exit")
    projects_menu = Wx::Menu.new
    projects_menu.append(1236,"New project")
    projects_menu.append(1237,"Load project")
    tools_menu = Wx::Menu.new
    tools_menu.append(1238,"Load file to ruby editor")
    tools_menu.append(1239,"Save file from ruby editor")
    help_menu = Wx::Menu.new
    help_menu.append(Wx::ID_ABOUT, "About...")
    @perspectives_menu = Wx::Menu.new
    @perspectives_menu.append( ID_CreatePerspective, 
                              "Create Perspective")
    @perspectives_menu.append( ID_CopyPerspectiveCode,
                              "Copy Perspective Data To Clipboard")
    @perspectives_menu.append_separator
    @perspectives_menu.append( ID_FirstPerspective + 0, "Default Startup")
    @perspectives_menu.append( ID_FirstPerspective + 1, "All Panes")
    mb.append(file_menu, "File")
    mb.append(tools_menu, "Tools")
    mb.append(projects_menu, "Projects")
    mb.append(@perspectives_menu, "Layout")
#     mb.append(notebook_menu, "Notebook")
    mb.append(help_menu, "Help")

    set_menu_bar(mb)
  end
  # create some toolbars
  def setup_toolbars
    tb1 = Wx::ToolBar.new( self, Wx::ID_ANY, 
                           Wx::DEFAULT_POSITION, 
                           Wx::DEFAULT_SIZE,
                           Wx::TB_FLAT|Wx::TB_NODIVIDER)
    tb1.set_tool_bitmap_size( Wx::Size.new(48,48) )
    tb1.add_tool( 101, "Test", 
                  Wx::ArtProvider::get_bitmap(Wx::ART_ERROR) )
    tb1.add_separator
    tb1.add_tool( 102, "Test", 
                  Wx::ArtProvider::get_bitmap(Wx::ART_QUESTION) )
    tb1.add_tool( 103, "Test", 
                  Wx::ArtProvider::get_bitmap(Wx::ART_INFORMATION) )
    tb1.add_tool( 103, "Test", 
                  Wx::ArtProvider::get_bitmap(Wx::ART_WARNING));
    tb1.add_tool( 103, "Test", 
                  Wx::ArtProvider::get_bitmap(Wx::ART_MISSING_IMAGE));
    tb1.realize
    # add the toolbars to the manager
    pi = Wx::AuiPaneInfo.new
    pi.set_name('tb1').set_caption("Toolbar 1").toolbar_pane
    pi.top.set_row(1)
    pi.set_left_dockable(false).set_right_dockable(false)
    @mgr.add_pane(tb1, pi)
  end

  def setup_panes
    pi = Wx::AuiPaneInfo.new
    pi.set_name('test8').set_caption('UI Menu').left
    pi.set_layer(1).set_position(1).set_close_button.set_maximize_button
    tree = create_tree_ctrl
    @tree_id = tree.get_id
    @mgr.add_pane(tree, pi)
    @log = create_text_ctrl("MuIDE version 0.02 running.\nWelcome to MuIDE!")
    wnd10 = @log
    pi = Wx::AuiPaneInfo.new
    pi.set_name('test10').set_caption('Mesages and I/O')
    pi.bottom.set_layer(1).set_position(1)
    @pM.add pi
    @mgr.add_pane(wnd10, pi) 
     
##########
    pi = Wx::AuiPaneInfo.new
    pi.set_name('editor_content').set_caption('Ruby Editor').show
    @pM.add pi
    @mgr.add_pane(create_editor, pi)
        @mgr.get_pane('editor_content').center
    pi = Wx::AuiPaneInfo.new
    pi.set_name('html_content').set_caption('Html viewr and Help').show(1)
    @mgr.add_pane(create_html_ctrl, pi)
    @pM.add pi
        @mgr.get_pane('html_content').center
    pi = Wx::AuiPaneInfo.new
    pi.set_name('yaml_content').set_caption('Yaml file viewr and editor').show
    pi.set_close_button.set_maximize_button
    @ye=YamlEditor::new self
    panel = @ye.panel	
    @mgr.add_pane(panel, pi)
    @pM.add pi
        @mgr.get_pane('yaml_content').center
    pi = Wx::AuiPaneInfo.new
    pi.set_layer(1).set_position(1).set_name('object_content').set_caption("Project Tree").right.show
    pi.set_close_button.set_maximize_button
    @ptree = ProjTree::new self
    @ptree_id = @ptree.get_id
    @mgr.add_pane(@ptree, pi)
    @pM.add pi

    pi = Wx::AuiPaneInfo.new
    pi.set_layer(1).set_position(1).set_name('proj1_edit').set_caption("Attribute Editor").show
    pi.set_close_button.set_maximize_button
    @pm = ProjectEditor::new(self)
    @mgr.add_pane(@pm.panel, pi)
    @pM.add pi
    @mgr.get_pane('proj1_edit').center

    pi = Wx::AuiPaneInfo.new
    pi.set_name('muclient_content').set_caption("Mu* Client").show
    pi.set_close_button.set_maximize_button
    @ui = ServerInterface::new(self)
    @mgr.add_pane(@ui.splitter, pi)
    @pM.add pi
    @mgr.get_pane('muclient_content').center

    pi = Wx::AuiPaneInfo.new
    ol=MuIDE::ObjectAttributeViewer::new(self)
    @object_list = ol.list
    pi.set_name('attViewer_content').set_layer(1).set_position(1).set_caption("Attribute viewer").show
    pi.set_close_button.set_maximize_button
    @mgr.add_pane(ol.panel, pi)
    @pM.add pi
    @mgr.get_pane('attViewer_content').center

    pi = Wx::AuiPaneInfo.new
    pi.set_name('extension_content').set_caption("Extension Manager").show
    pi.set_close_button.set_maximize_button
    @mgr.add_pane(ExtensionList::new(self).panel, pi)
    @pM.add pi
    @mgr.get_pane('extension_content').center

    pi = Wx::AuiPaneInfo.new
    pi.set_name('ilf_content').set_caption('Databases Tools').show
    pi.set_close_button.set_maximize_button
    @mgr.add_pane(ILFuncs::new(self).panel, pi)
        @mgr.get_pane('ilf_content').center
    @pM.add pi
########
  end
  def create_editor
    @styled = WxRide::EditorPage::new(self)
    return @styled
  end
  def create_tree_ctrl
    tree  = Wx::TreeCtrl.new( self, Wx::ID_ANY,
                              Wx::Point.new(0, 0), Wx::Size.new(160, 250),
                              Wx::TR_DEFAULT_STYLE|Wx::NO_BORDER)

    img_list = Wx::ImageList.new(16, 16, true, 2)
    img_list.add( Wx::ArtProvider::get_bitmap( Wx::ART_FOLDER, 
                                               Wx::ART_OTHER, 
                                               Wx::Size.new(16, 16) ) )
    img_list.add( Wx::ArtProvider::get_bitmap( Wx::ART_NORMAL_FILE, 
                                               Wx::ART_OTHER, 
                                               Wx::Size.new(16, 16) ) )
    tree.set_image_list(img_list)
    r = tree.add_root("Extensions", 0)
    root = tree.append_item(r,'Default',1)
    items = []
    @uiApps = ["Ruby Editor","Obj/Attr Viewer","Project Manager","YAML Viewer","GUI Server Interface","Extension Manager","Inter Library Functions","Html Viewer and Help"]
    @uiSubApps=File.open('data/extensions.ext',"r").readlines
    p @uiSubApps
    @uiApps.each { | i | items << tree.append_item(root, "#{i}", 1) }
    @uiAppItems = items
    p tree.methods
    root = tree.append_item(r,'Extra',1)
    items = []
    @uiSubApps.each { | i | items << tree.append_item(root, "#{i.gsub(/\n/,'')}", 1) }
    @uiSubAppItems = items
    tree.expand(r)
    tree
  end
  def create_html_ctrl(parent = nil)
    if not parent
      parent = self
    end
    panel = Wx::Panel::new self,-1
    ctrl = Wx::HtmlWindow.new(panel, Wx::ID_ANY,
                               Wx::DEFAULT_POSITION,
                               Wx::Size.new(500, 300) )
    ctrl.set_page(DATA.read)
    panel.set_sizer Wx::BoxSizer::new(Wx::HORIZONTAL)
    panel.sizer.add ctrl,Wx::GROW|Wx::ALL,Wx::EXPAND
    siz=Wx::StaticBoxSizer::new Wx::VERTICAL,panel,"Help and HTML Viewer"
    @helptree = HelpTree::new ctrl,panel,-1,:size=>Wx::Size::new(250,-1)
    siz.add @helptree,Wx::GROW|Wx::ALL,Wx::EXPAND
    siz.add Wx::Button::new panel,9876,"View HTML File"
    panel.sizer.add siz,0,Wx::EXPAND
    panel
  end

  def create_notebook
    # create the notebook off-window to avoid flicker
    client_size = get_client_size

    ctrl = Wx::AuiNotebook.new( self, Wx::ID_ANY,
                                Wx::Point.new(client_size.x, client_size.y),
                                Wx::Size.new(430, 200),
                                @notebook_style)
    
    page_bmp = Wx::ArtProvider::get_bitmap( Wx::ART_NORMAL_FILE, 
                                            Wx::ART_OTHER, 
                                            Wx::Size.new(16,16) )
    
    ctrl.add_page( create_html_ctrl(ctrl), 
                   "Welcome to Wx::AUI", false, page_bmp)
    
    panel = Wx::Panel.new(ctrl, Wx::ID_ANY)
    flex = Wx::FlexGridSizer.new( 2 )
    flex.add_growable_row( 0 )
    flex.add_growable_row( 3 )
    flex.add_growable_row( 1 )
    
    flex.add( 5, 5 )
    flex.add( 5, 5 )
    flex.add( Wx::StaticText.new( panel, -1, "Wx::TextCtrl:" ), 
              0, Wx::ALL|Wx::ALIGN_CENTRE, 5 )
    flex.add( Wx::TextCtrl.new( panel, -1, "", 
                                Wx::DEFAULT_POSITION, Wx::Size.new(100,-1) ), 
              1, Wx::ALL|Wx::ALIGN_CENTRE, 5 )

    flex.add( Wx::StaticText.new( panel, -1, "Wx::SpinCtrl:" ), 
              0, Wx::ALL|Wx::ALIGN_CENTRE, 5 )
    flex.add( Wx::SpinCtrl.new( panel, -1, "5", 
                                Wx::DEFAULT_POSITION, Wx::Size.new(100,-1), 
                                Wx::SP_ARROW_KEYS, 5, 50, 5 ), 
              1, Wx::ALL|Wx::ALIGN_CENTRE, 5 )

    flex.add( 5,5 )
    flex.add( 5,5 )
    panel.set_sizer( flex )
    ctrl.add_page( panel, "wxPanel", false, page_bmp )
    
    
    ctrl.add_page( Wx::TextCtrl.new( ctrl, Wx::ID_ANY, "Some text",
                                     Wx::DEFAULT_POSITION, Wx::DEFAULT_SIZE, 
                                     Wx::TE_MULTILINE|Wx::NO_BORDER),
                   "wxTextCtrl 1", false, page_bmp )

    ctrl.add_page( Wx::TextCtrl.new( ctrl, Wx::ID_ANY, "Some more text",
                                     Wx::DEFAULT_POSITION, Wx::DEFAULT_SIZE, 
                                     Wx::TE_MULTILINE|Wx::NO_BORDER),
                   "wxTextCtrl 2" )

    ctrl.add_page( Wx::TextCtrl.new( ctrl, Wx::ID_ANY, "Some more text",
                                     Wx::DEFAULT_POSITION, Wx::DEFAULT_SIZE, 
                                     Wx::TE_MULTILINE|Wx::NO_BORDER),
                   "wxTextCtrl 3" )

    ctrl.add_page( Wx::TextCtrl.new( ctrl, Wx::ID_ANY, "Some more text",
                                     Wx::DEFAULT_POSITION, Wx::DEFAULT_SIZE, 
                                     Wx::TE_MULTILINE|Wx::NO_BORDER),
                   "wxTextCtrl 4" )

    ctrl.add_page( Wx::TextCtrl.new( ctrl, Wx::ID_ANY, "Some more text",
                                     Wx::DEFAULT_POSITION, Wx::DEFAULT_SIZE, 
                                     Wx::TE_MULTILINE|Wx::NO_BORDER),
                   "wxTextCtrl 5" )

    ctrl.add_page( Wx::TextCtrl.new( ctrl, Wx::ID_ANY, "Some more text",
                                     Wx::DEFAULT_POSITION, Wx::DEFAULT_SIZE, 
                                     Wx::TE_MULTILINE|Wx::NO_BORDER),
                   "wxTextCtrl 6" )

    ctrl.add_page( Wx::TextCtrl.new( ctrl, Wx::ID_ANY, "Some more text",
                                     Wx::DEFAULT_POSITION, Wx::DEFAULT_SIZE, 
                                     Wx::TE_MULTILINE|Wx::NO_BORDER),
                   "wxTextCtrl 7 (longer title)" )

    ctrl.add_page( Wx::TextCtrl.new( ctrl, Wx::ID_ANY, "Some more text",
                                     Wx::DEFAULT_POSITION, Wx::DEFAULT_SIZE, 
                                     Wx::TE_MULTILINE|Wx::NO_BORDER),
                   "wxTextCtrl 8" )
    return ctrl
  end
  def create_text_ctrl(text = "")
    if text.empty?
      text = "This is a test text box"
    end
    Wx::TextCtrl.new( self, Wx::ID_ANY, text, 
                      Wx::Point.new(0, 0), Wx::Size.new(150, 90),
                      Wx::NO_BORDER|Wx::TE_MULTILINE)
  end
  def on_create_perspective
    msg = "Enter a name for the new perspective:"
    dlg = Wx::TextEntryDialog.new(self, msg, "Wx::AUI Test")
    dlg.set_value("Perspective %d" % [ @perspectives.length + 1 ] )
    return unless dlg.show_modal == Wx::ID_OK
    if @perspectives.length.zero?
      @perspectives_menu.append_separator
    end
p ID_FirstPerspective
p ID_FirstPerspective + @perspectives.length
    @perspectives_menu.append(ID_FirstPerspective + @perspectives.length,
                               dlg.get_value)
    @perspectives << @mgr.save_perspective
p @perspectives.length
  end

  def on_copy_perspective_code
#     Kernel.raise NotImplementedError
  end
  def setup_perspectives
    perspective_all = @mgr.save_perspective

    @mgr.each_pane do | pane | 
      pane.hide unless pane.is_toolbar
    end 

    @mgr.get_pane("test8").show
#     @mgr.get_pane("tb6").hide
    @mgr.get_pane("html_content").show.top.set_layer(0).set_row(0).set_position(0)
    @mgr.get_pane("test10").show.bottom.set_layer(0).set_row(0).set_position(0)
#     @mgr.get_pane("viewingNB").show().set_layer(0).set_row(0).set_position(0)
        @mgr.get_pane("toolNB").show()
    perspective_default = @mgr.save_perspective

    @perspectives << perspective_default
    @perspectives << perspective_all
  end
  def on_restore_perspective(event)
    perspective = @perspectives[ event.get_id - ID_FirstPerspective]
p perspective
    @mgr.load_perspective(perspective)
  end
  end
  class BaseAPP < Wx::App
    def on_init
      baseFrame = MuIDE::BaseGUIframe::new(["parent", nil],["id", -1],["name", "MuIDE! ruby/MU* bindings, mu* intergrated dev enviroment, mu-client and more."])
      baseFrame.show
    end
  end
  class Initializer
    def initialize(args)
      args.each do |arg|
       if arg[0] =~ /parent/
         @ins_parent = arg[1]
       elsif arg[0] =~ /id/
         @ins_id = arg[1]
       elsif arg[0] =~ /name/
         @ins_name = arg[1]
       else
       end
      end
    end
    def super_frame
      return [@ins_parent,@ins_id,@ins_name]
    end
  end 
end
$app = MuIDE::BaseAPP::new
$app.main_loop()
__END__
<html>
<body>
foo<br>foo
</body></html>

